<?php

namespace addons\mydemo;

use app\common\library\Menu;
use think\Addons;

/**
 * Mydemo插件
 */
class Mydemo extends Addons
{
    protected $menu = [
        [
            'name'      => 'mydemo', //权限规则标识，首个菜单标识必须和插件标识相同
            'title'     => 'Mydemo管理', //菜单标题
            'icon'      => 'fa fa-map-marker', //菜单按钮，可使用Font-Awesome的图标
            'ismenu'    => 1, //是否为菜单
            'listorder' => 1, //权重，值越大越靠前
            'sublist'   => [ //子菜单配置，子菜单name必须以 插件标识/ 开始，这里如 mydemo/
                ["name" => "mydemo/signin/index", "title" => "查看"],
                ["name" => "mydemo/signin/add", "title" => "添加"],
                ["name" => "mydemo/signin/edit", "title" => "编辑"],
                ["name" => "mydemo/signin/del", "title" => "删除"],
                ["name" => "mydemo/signin/multi", "title" => "批量更新"],
            ],
        ],
    ];
    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        Menu::create($this->menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("mydemo");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("mydemo");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("mydemo");
        return true;
    }

    /**
     * 插件升级方法
     * @return bool
     */
    public function upgrade()
    {
        //如果菜单有变更则升级菜单
        Menu::upgrade('mydemo', $this->menu);
        return true;
    }

}
